package text2;
import java.io.*;
import java.util.*;
public class Experiment4 { public static void main(String args[]) {
    File file = new File("D:/zqj/StuPC/src/text2/zqj.txt");
    Scanner sc = null;
    int count = 0;
    double sum = 0;
    try {
        int score = 0;
        sc = new Scanner(file);
        sc.useDelimiter("[^0123456789]+" );
        while (sc.hasNextDouble()) {

            score = (int)sc.nextDouble();
            count++;
            sum = sum + score;

            System.out.println(score+"元/台");
        }
        double aver = sum / count;
        String str = String.format("%d", (int)aver);
        System.out.println("平均价格:" + str+"元");

            FileWriter fw = new FileWriter(file, true);
            BufferedWriter bw = new BufferedWriter(fw);
            bw.write("");
            bw.write("平均价格: " + str + " /台\n");
            bw.close();
        }
    catch (Exception exp) {
        System.out.println(exp);
    }
    }
}
